﻿Option Explicit On
'Imports System.Runtime.InteropServices

'Imports System.Drawing
'NavalTargeting,MovementZone,Locomotor,Factory,ExtraPower,Armor,BuildCat,Category,EliteAbilities,PipScale,Prerequisite,SpeedType

Public Class frmMain
    Const WM_DROPFILES = &H233

    Public iSection As KeyValue.INISection()
    Public iCom As KeyValue.Cite()
    Public iClipboard As New ArrayList
    Dim tmpReg As modReg.RegClass.RegUnit

    Private fineshedCC As Boolean
    Private allowAddBookmark As Boolean = True
    Private allowChangeSectionRTF As Boolean = True

    Dim tmpSSArray As String()
    Private canAutoCom As Boolean = True
    Private lastViewedSection As Integer = -1
    Private lastViewedSIndex As Long = -1
    Private CCD As New CodeColorLibrary.CodeColor

    Dim FontC, BackC, C1, C2, C3, strC, strC1 As Color

    Public ccdFunctions As String = ""
    Dim orgSS As Integer

    Public rtfCtrlKey As Boolean '= False
    Public rtfAltKey As Boolean '= False
    Public currentFile As String = ""

    Public Modifyed = False

    'Dim RulesAutoItems As New System.Windows.Forms.ListBox.ObjectCollection(lstAutoCRules)
    'Dim ObjectAutoItems As New System.Windows.Forms.ListBox.ObjectCollection(lstAutoCObject)
    Public RulesCodeData As KeyValue.INICodeData

    Public Sub CheckClipboardArray()

        'If Me.iClipboard IsNot Nothing Then
        If Me.iClipboard.Count < 5 Then
            Do Until iClipboard.Count = 5
                iClipboard.Add("")
            Loop
        ElseIf Me.iClipboard.Count > 5 Then
            Do Until iClipboard.Count = 5
                iClipboard.RemoveAt(0)
            Loop
        End If
        'Else
        'End If

    End Sub

    Public Sub CheckParentFormClipboardList()

        Dim ParentForm As frmMDIParent
        ParentForm = DirectCast(Me.MdiParent, frmMDIParent)

        If ParentForm IsNot Nothing Then
            ParentForm.lstClipboard.Items.Clear()
            For Each Text As String In iClipboard

                If Trim(Text) <> "" And Text <> Nothing Then ParentForm.lstClipboard.Items.Add(Text)

            Next
        End If

    End Sub

    Private Sub frmMain_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        If e.KeyCode = Keys.Left And e.Alt = True Then
            cmdBack_Click(cmdBack, e)
        End If
    End Sub

    Private Sub Form1_Load(ByVal ser As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lblBuild.Text = "Build : " + My.Application.Info.Version.ToString '+ "." + My.Application.Info.Version.Revision.ToString 'System.Reflection.Assembly.GetExecutingAssembly().FullName
        'Me.Text = "INI文件通用编辑器 by SecondDatke 2011 Version 2." + CInt(My.Application.Info.Version.Revision / 7000).ToString + "." + CInt(My.Application.Info.Version.Revision / 75).ToString

        'tmpReg.UnitType = New ArrayList
        'tmpReg.UnitName = New ArrayList

        With RichTextBox2      '对Triche2dit控件进行设置
            If .WordWrap Then .WordWrap = False
            .SelectAll()
            '.SelAttributes.color = Color.Black
            .SelectionColor = Color.Black
            'SelAttributes.Style = []
            .SelectionStart = 0
        End With

        BackC = Color.White
        FontC = Color.Black
        C1 = Color.Teal
        C2 = Color.Maroon
        C3 = Color.Blue
        strC = Color.Maroon
        strC1 = Color.Silver

        Me.rtfText.AllowDrop = True

        'RulesCodeData
        Dim Rfs As New System.IO.FileStream(Application.StartupPath + "\Data\rules.sdl", IO.FileMode.Open)
        Dim Rsr As New System.IO.StreamReader(Rfs, System.Text.Encoding.GetEncoding("GB2312"))
        RulesCodeData.CodeName = New ArrayList
        RulesCodeData.CodeMean = New ArrayList

        Do Until Rsr.EndOfStream
            Dim currentLine As String = Rsr.ReadLine
            If currentLine <> Nothing And currentLine <> "" Then
                If UBound(currentLine.Split("|")) >= 1 Then
                    RulesCodeData.CodeName.Add(currentLine.Split("|")(0))
                    RulesCodeData.CodeMean.Add(currentLine.Split("|")(1))
                End If
            End If
        Loop

        Rsr.Close()
        lstAutoCRules.Items.Clear()
        For Each Code In RulesCodeData.CodeName
            lstAutoCRules.Items.Add(Code)
        Next
        'tmpRTF.Text = Rsr.ReadToEnd

        CheckClipboardArray()
        CheckParentFormClipboardList()

    End Sub

    Public Sub LoadFile(ByVal Param As Integer, Optional ByVal FileName As String = "")
        'OpenFile.InitialDirectory = "c:\"
        If Param = 0 Then
            OpenFile.Filter = "INI文件 (*.ini)|*.ini|所有文件 (*.*)|*.*"
            'OpenFile.RestoreDirectory = True

            If OpenFile.ShowDialog() = DialogResult.OK Then

                For Each Form As frmMain In Me.MdiParent.MdiChildren
                    If Form.currentFile = OpenFile.FileName Then
                        MsgBox("正在打开的文件与已经打开的文件出现重复，打开操作已经中止。", MsgBoxStyle.OkOnly + MsgBoxStyle.Exclamation, "INI编辑器 V2 警告")
                        Exit Sub
                    End If
                Next

                iSection = cSection.GetSectionContextArrayFromFile(OpenFile.FileName, rtfFile)
                lstSection.Items.Clear()
                lstAutoC.Items.Clear()
                lstAutoC.Sorted = True
                lastViewedSection = -1
                For Each root As KeyValue.INISection In iSection
                    If root.SectionName <> Nothing Then
                        lstSection.Items.Add(root.SectionName)
                        'lstAutoC.Items.Add(root.SectionName)

                        If ccdFunctions = "" Then
                            ccdFunctions = root.SectionName
                        Else
                            ccdFunctions = ccdFunctions + "," + root.SectionName
                        End If
                        currentFile = OpenFile.FileName
                        Me.Text = OpenFile.SafeFileName
                        If lstSection.Items.Count >= 1 Then
                            lstSection.SelectedIndex = 0
                            'lstAutoC.SelectedIndex = 0
                        End If
                    End If
                Next
                Me.lstBookmark.Items.Clear()
                UpdateObjectListArray()
                Dim ParentForm As frmMDIParent
                ParentForm = DirectCast(Me.MdiParent, frmMDIParent)
                If ParentForm.RecentFile.IndexOf(currentFile) < 0 Then
                    ParentForm.RecentFile.Insert(0, currentFile)
                    ParentForm.EightNumberRFA()
                    ParentForm.RefreshRecentFileMenuItem()
                End If
                Modifyed = False
                'tmpReg = cReg.GetRegInfoArray(iSection)
            End If

        ElseIf Param = 1 Then

            If System.IO.File.Exists(FileName) = False Then
                MsgBox("该文件不存在，打开操作已经中止。请检查路径和文件名的正确性。", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, "INI编辑器 V2 警告")
                Exit Sub
            End If

            For Each Form As frmMain In Me.MdiParent.MdiChildren
                If Form.currentFile = FileName Then
                    MsgBox("正在打开的文件与已经打开的文件出现重复，打开操作已经中止。", MsgBoxStyle.OkOnly + MsgBoxStyle.Exclamation, "INI编辑器 V2 警告")
                    Exit Sub
                End If
            Next

            iSection = cSection.GetSectionContextArrayFromFile(FileName, rtfFile)
            lstSection.Items.Clear()
            lstAutoC.Items.Clear()
            lstAutoC.Sorted = True
            lastViewedSection = -1
            For Each root As KeyValue.INISection In iSection
                If root.SectionName <> Nothing Then
                    lstSection.Items.Add(root.SectionName)
                    'lstAutoC.Items.Add(root.SectionName)

                    If ccdFunctions = "" Then
                        ccdFunctions = root.SectionName
                    Else
                        ccdFunctions = ccdFunctions + "," + root.SectionName
                    End If
                    currentFile = FileName
                    Me.Text = GetSafeFileName(FileName)
                    If lstSection.Items.Count >= 1 Then
                        lstSection.SelectedIndex = 0
                        'lstAutoC.SelectedIndex = 0
                    End If
                End If
            Next
            Me.lstBookmark.Items.Clear()
            UpdateObjectListArray()
            Modifyed = False

        ElseIf Param = 2 Then

            If System.IO.File.Exists(FileName) = False Then
                MsgBox("该文件不存在，打开操作已经中止。请检查路径和文件名的正确性。", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, "INI编辑器 V2 警告")
                Exit Sub
            End If

            For Each Form As frmMain In Me.MdiParent.MdiChildren
                If Form.currentFile = FileName Then
                    MsgBox("正在打开的文件与已经打开的文件出现重复，打开操作已经中止。", MsgBoxStyle.OkOnly + MsgBoxStyle.Exclamation, "INI编辑器 V2 警告")
                    Exit Sub
                End If
            Next

            iSection = cSection.GetSectionContextArrayFromFile(FileName, rtfFile)
            lstSection.Items.Clear()
            lstAutoC.Items.Clear()
            lstAutoC.Sorted = True
            lastViewedSection = -1
            For Each root As KeyValue.INISection In iSection
                If root.SectionName <> Nothing Then
                    lstSection.Items.Add(root.SectionName)
                    'lstAutoC.Items.Add(root.SectionName)

                    If ccdFunctions = "" Then
                        ccdFunctions = root.SectionName
                    Else
                        ccdFunctions = ccdFunctions + "," + root.SectionName
                    End If
                    currentFile = FileName
                    Me.Text = GetSafeFileName(FileName)
                    If lstSection.Items.Count >= 1 Then
                        lstSection.SelectedIndex = 0
                        'lstAutoC.SelectedIndex = 0
                    End If
                End If
            Next
            Me.lstBookmark.Items.Clear()
            UpdateObjectListArray()
            Dim ParentForm As frmMDIParent
            ParentForm = DirectCast(Me.MdiParent, frmMDIParent)
            If ParentForm.RecentFile.IndexOf(currentFile) < 0 Then
                ParentForm.RecentFile.Insert(0, currentFile)
                ParentForm.EightNumberRFA()
                ParentForm.RefreshRecentFileMenuItem()
            End If
            Modifyed = False

        End If

    End Sub

    Private Sub rtfText_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rtfText.Click
        lbltestLine.Text = GetCurrentWord.WordContext
        lblType.Text = GetCurrentWord.LineType

        If Me.MdiParent IsNot Nothing Then
            Dim ParentForm As frmMDIParent
            ParentForm = DirectCast(Me.MdiParent, frmMDIParent)
            ParentForm.stlWord.Text = lbltestLine.Text
        End If

        If rtfCtrlKey = True Then
            'lstSection.SelectedIndex = lstSection.SelectedIndex + 1
            Dim curStr As String
            Dim curIndex As Integer
            'findIndex = lstSection.FindString(txtSFind.Text)
            'lstSection.SelectedIndex = findIndex

            If lstSection.SelectedIndex > 0 Then
                curStr = lstSection.SelectedItem
                If curStr.IndexOf(GetCurrentWord().WordContext) <> -1 Then
                    curIndex = lstSection.SelectedIndex + 1
                Else
                    curIndex = lstSection.SelectedIndex
                End If

            End If
            'For Each item In lstSection.Items
            'Next

            For i = 0 To lstSection.Items.Count - 1

                If i > 0 Then
                    curStr = lstSection.Items(i)
                    If curStr.ToLower.IndexOf(GetCurrentWord().WordContext.ToLower) <> -1 Then
                        lstSection.SelectedIndex = i
                        Exit For
                    End If
                End If

            Next
        End If

        'lblBuild.Text = CStr(UBound(rtfText.Lines(CheckRow2).ToCharArray))
    End Sub

    Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rtfText.TextChanged
        'CodeColors2(Me, "Default", RichTextBox1, RichTextBox2)
        lbltestLine.Text = GetCurrentWord.WordContext 'CStr(CheckCol(rtfText))
        lblType.Text = GetCurrentWord.LineType

        If Me.MdiParent IsNot Nothing Then
            Dim ParentForm As frmMDIParent
            ParentForm = DirectCast(Me.MdiParent, frmMDIParent)
            ParentForm.stlWord.Text = lbltestLine.Text
        End If
        ''lblBuild.Text = GetCurrentWord.LineType
        'CodeColors2(Me, "Default", rtfText, RichTextBox2)
        'CodeColor4()
        'lstAutoC.Location = 
        'CodeColors(Me, "Default", RichTextBox1, RichTextBox2)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        CodeColor4()
    End Sub

    Private Sub lstSection_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstSection.DoubleClick
        'Dim cuLine As String = ""
        'Dim SectionText As String = ""
        'Dim fs As New System.IO.FileStream("E:\VMWARE\FD77CARE\rulesmd.ini", IO.FileMode.Open)
        'Dim sr As New System.IO.StreamReader(fs)
        'While Microsoft.VisualBasic.Left(cuLine, lstSection.SelectedItem.Length + 2) <> "[" + lstSection.SelectedItem + "]"
        'cuLine = sr.ReadLine
        'tmpRTF.Text = sr.ReadToEnd
        'End While
        'While Microsoft.VisualBasic.Left(cuLine, 1) <> "[" Or Microsoft.VisualBasic.Left(cuLine, lstSection.SelectedItem.Length + 2) = "[" + lstSection.SelectedItem + "]"
        'SectionText = SectionText + vbCrLf + cuLine
        'cuLine = sr.ReadLine
        'End While
        'sr.Close()
        'fs.Close()

        'RichTextBox1.Text = SectionText
    End Sub

    Private Sub lstSection_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstSection.SelectedIndexChanged
        If rtfText.Text <> "" And lastViewedSection <> -1 Then
            iSection(lastViewedSection).SectionContext = rtfText.Text
        End If

        If lstSection.SelectedIndex >= 0 Then
            rtfText.Text = iSection(lstSection.SelectedIndex).SectionContext
            lastViewedSection = lstSection.SelectedIndex
            CodeColor4()
        End If

        If allowAddBookmark = True Then

            If lstSection.SelectedItem <> Nothing Then
                lstBookmark.Items.Add(lstSection.SelectedItem)
            End If

            If lstBookmark.FindStringExact(lstSection.SelectedItem) >= 0 And lstBookmark.FindStringExact(lstSection.SelectedItem) <> lstBookmark.Items.Count - 1 Then
                lstBookmark.Items.RemoveAt(lstBookmark.FindStringExact(lstSection.SelectedItem))
            End If

            lstBookmark.SelectedIndex = lstBookmark.Items.Count - 1

            'If lstBookmark.Items.Count > 8 Then lstBookmark.Items.RemoveAt(0)
            'If lstBookmark.Items.Count > 16 Then lstBookmark.Items.RemoveAt(0)
            'If lstBookmark.Items.Count > 12 Then lstBookmark.Items.RemoveAt(0)
            If lstBookmark.Items.Count > 14 Then lstBookmark.Items.RemoveAt(0)

        End If

        If lstAutoC.Visible = True Then
            lstAutoC.Visible = False
        End If

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If rtfText.Text <> "" Then
            iSection(lstSection.SelectedIndex).SectionContext = rtfText.Text
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        SaveINI()
    End Sub

    Public Sub cmdFindNext_Click() Handles cmdFindNext.Click, cmdFindNextP.Click
        GFindNext(txtFind.Text)
    End Sub

    Public Sub GFindNext(ByVal Text As String)
        Dim tmpFind As Integer
        tmpFind = rtfText.Find(Text, rtfText.SelectionStart + rtfText.SelectionLength, RichTextBoxFinds.NoHighlight)

        If Text <> "" Then
            If tmpFind >= 0 Then
                bAllowCodeColor = False
                rtfText.SelectionStart = tmpFind
                rtfText.SelectionLength = Text.Length
                rtfText.SelectionBackColor = Color.Red

                RichTextBox2.SelectionStart = tmpFind
                RichTextBox2.SelectionLength = Text.Length
                RichTextBox2.SelectionBackColor = Color.Red

                tmpFind = rtfText.Find(Text, rtfText.SelectionStart + rtfText.SelectionLength, RichTextBoxFinds.NoHighlight)
                'bAllowCodeColor = True
                'RichTextBox1.Select(tmpFind, text.Length)
            Else
                lstSection.SelectedIndex = cSection.SearchInArray(iSection, lstSection.SelectedIndex, Text, True)
                tmpFind = rtfText.Find(Text, rtfText.SelectionStart + rtfText.SelectionLength, RichTextBoxFinds.NoHighlight)
                bAllowCodeColor = False
                'RichTextBox1.Select(tmpFind, text.Length)
                'RichTextBox1.SelectionBackColor = Color.White
                If tmpFind >= 0 Then
                    rtfText.SelectionStart = tmpFind
                    rtfText.SelectionLength = Text.Length
                    rtfText.SelectionBackColor = Color.Red
                End If

                'bAllowCodeColor = True
            End If

            bAllowCodeColor = True
        End If
    End Sub

    Public Sub GFindPrev(ByVal Text As String)
        Dim tmpFind As Integer
        tmpFind = rtfText.Find(Text, rtfText.SelectionStart + rtfText.SelectionLength, RichTextBoxFinds.NoHighlight)

        If Text <> "" Then
            If tmpFind >= 0 Then
                bAllowCodeColor = False
                rtfText.SelectionStart = tmpFind
                rtfText.SelectionLength = Text.Length
                rtfText.SelectionBackColor = Color.Red

                RichTextBox2.SelectionStart = tmpFind
                RichTextBox2.SelectionLength = Text.Length
                RichTextBox2.SelectionBackColor = Color.Red

                tmpFind = rtfText.Find(Text, rtfText.SelectionStart + rtfText.SelectionLength, RichTextBoxFinds.NoHighlight)
                'bAllowCodeColor = True
                'RichTextBox1.Select(tmpFind, text.Length)
            Else
                lstSection.SelectedIndex = cSection.SearchInArray(iSection, lstSection.SelectedIndex, Text, False)

                tmpFind = rtfText.Find(Text, 0, RichTextBoxFinds.NoHighlight)
                bAllowCodeColor = False
                'RichTextBox1.Select(tmpFind, text.Length)
                'RichTextBox1.SelectionBackColor = Color.White
                rtfText.SelectionStart = tmpFind
                rtfText.SelectionLength = Text.Length
                rtfText.SelectionBackColor = Color.Red

                RichTextBox2.SelectionStart = tmpFind
                RichTextBox2.SelectionLength = Text.Length
                RichTextBox2.SelectionBackColor = Color.Red

                'bAllowCodeColor = True
            End If

            bAllowCodeColor = True
        End If
    End Sub

    Public Sub cmdFindPrev_Click() Handles cmdFindPrev.Click, cmdFindPrevP.Click
        GFindPrev(txtFind.Text)
    End Sub

    Public Sub SFindNext(ByVal Text As String)
        Dim tmpFind As Integer
        tmpFind = rtfText.Find(Text, rtfText.SelectionStart + rtfText.SelectionLength, RichTextBoxFinds.NoHighlight)

        If Text <> "" Then
            If tmpFind >= 0 Then
                bAllowCodeColor = False
                rtfText.SelectionStart = tmpFind
                rtfText.SelectionLength = Text.Length
                rtfText.SelectionBackColor = Color.Red
                tmpFind = rtfText.Find(Text, rtfText.SelectionStart + rtfText.SelectionLength, RichTextBoxFinds.NoHighlight)
            Else
                tmpFind = rtfText.Find(Text, 0, RichTextBoxFinds.NoHighlight)
                If tmpFind >= 0 Then
                    rtfText.SelectionStart = tmpFind
                    rtfText.SelectionLength = Text.Length
                    rtfText.SelectionBackColor = Color.Red
                End If
            End If
        End If

    End Sub

    Private Sub cmdSFind_Click() Handles cmdSFind.Click
        Dim curStr As String
        Dim curIndex As Integer

        If lstSection.SelectedIndex > 0 Then
            curStr = lstSection.SelectedItem
            If curStr.IndexOf(txtSFind.Text) <> -1 Then
                curIndex = lstSection.SelectedIndex + 1
            Else
                curIndex = lstSection.SelectedIndex
            End If

        End If

        'For i = curIndex + 1 To lstSection.Items.Count - 1
        For i = curIndex To lstSection.Items.Count - 1
            If i > 0 Then
                curStr = lstSection.Items(i)
                If curStr.ToLower.IndexOf(txtSFind.Text.ToLower) <> -1 Then
                    lstSection.SelectedIndex = i
                    Exit For
                Else
                    If lstSection.FindString(txtSFind.Text) >= 0 Then
                        lstSection.SelectedIndex = lstSection.FindString(txtSFind.Text)
                    End If
                End If
            End If
        Next
    End Sub

    Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
        If txtSFind.Text <> "" Then
            'Dim orgLocation As Integer = lstSection.SelectedIndex + 2
            Dim orgLocation As Integer = lstSection.SelectedIndex + 1

            iSection = cSection.InsertSection(iSection, orgLocation, txtSFind.Text)

            lstSection.Items.Clear()
            'For Each root As String In tmpSSArray
            For Each root As KeyValue.INISection In iSection
                If root.SectionName <> Nothing Then lstSection.Items.Add(root.SectionName)
            Next

            lstSection.SelectedIndex = orgLocation
        End If
    End Sub

    Private Sub cmdtestLine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdtestLine.Click
        lbltestLine.Text = (GetCurrentLineStr())
    End Sub

    Private Sub cmdAllCom_Click() Handles cmdAllCom.Click, cmdAllComP.Click
        If Me.currentFile <> "" And Me.currentFile <> Nothing Then
            ReDim iCom(0)
            ReDim iCom(iCom.Length - 1).LineContext(0)
            Dim curSContextLines As String()
            Dim searchFor As String = rtfText.SelectedText

            If rtfText.SelectedText = "" Then
                searchFor = GetCurrentWord().WordContext
            End If

            'lblCom.Text = searchFor

            For Each Section In iSection
                If InStr(Section.SectionContext, searchFor) <> 0 Then
                    'ReDim Preserve iCom(iCom.Length + 1)
                    ReDim Preserve iCom(UBound(iCom) + 1)
                    'ReDim Preserve iCom(iCom.Length - 1).LineContext(0)
                    ReDim Preserve iCom(UBound(iCom)).LineContext(0)

                    iCom(iCom.Length - 1).SectionName = Section.SectionName
                    curSContextLines = ConvertStringToLines(Section.SectionContext)

                    'For Each Line In curSContextLines
                    'MsgBox(Line)
                    'Next
                    For Each Line In curSContextLines
                        If InStr(Line, searchFor) <> 0 Then
                            iCom(UBound(iCom)).LineContext(UBound(iCom(UBound(iCom)).LineContext)) = Line
                            ReDim Preserve iCom(iCom.Length - 1).LineContext(UBound(iCom(iCom.Length - 1).LineContext) + 1)
                        End If
                    Next
                End If
            Next

            trvCom.Nodes.Clear()
            For Each Section In iCom
                If Section.SectionName <> Nothing Then
                    trvCom.Nodes.Add(Section.SectionName)
                    For Each Line In Section.LineContext
                        If Line <> Nothing Then
                            trvCom.Nodes.Item(trvCom.Nodes.Count - 1).Nodes.Add(Line)
                        End If
                    Next
                End If
            Next

            '需要添加判断数目代码
            trvCom.ExpandAll()

        End If

    End Sub

    Private Sub trvCom_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles trvCom.DoubleClick

        If trvCom.SelectedNode IsNot Nothing Then
            If trvCom.SelectedNode.Level = 0 Then
                lstSection.SelectedItem = trvCom.SelectedNode.Text
            Else
                lstSection.SelectedItem = trvCom.SelectedNode.Parent.Text
                rtfText.Text = iSection(lstSection.SelectedIndex).SectionContext
                CodeColor4()
                'rtfText.SelectionStart = rtfText.Find(Trim(trvCom.SelectedNode.Text), RichTextBoxFinds.WholeWord)
                'rtfText.SelectionLength = trvCom.SelectedNode.Text.Length
                If rtfText.Find(Trim(trvCom.SelectedNode.Text), RichTextBoxFinds.NoHighlight) <> -1 Then
                    fineshedCC = True
                    rtfText.Select(rtfText.Find(Trim(trvCom.SelectedNode.Text), RichTextBoxFinds.NoHighlight), trvCom.SelectedNode.Text.Length)
                    rtfText.SelectionBackColor = Color.Green

                    'rtfText.SelectionStart = tmpFind
                    'rtfText.SelectionLength = txtFind.Text.Length
                    'rtfText.SelectionBackColor = Color.Red
                    'rtfText.Select(rtfText.Find(Trim(trvCom.SelectedNode.Text), RichTextBoxFinds.MatchCase), trvCom.SelectedNode.Text.Length)
                End If
                'rtfText.Refresh()
            End If
        End If

    End Sub

    Private Function GetCurrentLineStr() As String
        Return GetLinesArray(CheckRow2) 'CheckRow(True))
    End Function

    Private Function GetLinesArray() As String()
        Dim Lines As String()
        'Lines = rtfText.Text.Split(vbCrLf)

        Lines = rtfText.Lines

        Return (Lines)
    End Function

    Private Function CheckRow1(ByVal ReturnRow As Boolean) As Integer

        Dim row As Integer = Me.rtfText.SelectionStart
        Dim i As Integer
        Dim p As Integer
        Dim count As Integer = 0
        Dim count1 As Integer = 0

        Dim curRow As Integer
        Dim curLie As Integer
        For i = 0 To Me.rtfText.Lines.GetUpperBound(0)

            count += Me.rtfText.Lines(i).Length + 1   '   一个回车相当于1个字符

            If row < count Then
                If i = 0 Then
                    p = row   '就一行的话
                Else
                    p = row - count1
                End If
                curRow = i
                curLie = p
                'Return "行： " & CStr(i) & "/列： " & CStr(p)
            ElseIf row = count Then

                p = 0
                curRow = i + 1
                curLie = p
                'Return "行： " & CStr(i + 1) & "/列： " & CStr(p)
            End If
            count1 += Me.rtfText.Lines(i).Length + 1

        Next

        If ReturnRow = True Then
            Return curRow
        ElseIf ReturnRow = False Then
            Return curLie
        End If

    End Function

    Private Function CheckRow2() As Integer
        Dim intRet As Integer
        intRet = SendMessage(Me.rtfText.Handle.ToInt32, EM_EXLINEFROMCHAR, 0, Me.rtfText.SelectionStart)
        Return intRet
    End Function

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        MsgBox(CStr((cReg.GetFinalNum(iSection, "BuildingTypes"))))
    End Sub

    Private Function CheckCol(ByVal rtf As RichTextBox) As Integer
        Dim intCurPos As Integer = rtf.SelectionStart
        Dim intLineNo As Integer = CheckRow2() 'SendMessage(rtf.Handle.ToInt32, EM_EXLINEFROMCHAR, 0, rtf.SelectionStart) 'rtf.GetLineFromCharIndex(intCurPos)
        Dim intColNo1 As Integer
        Dim intColNo As Integer

        intColNo1 = SendMessage(rtf.Handle.ToInt32, &HBB, intLineNo, 0)
        intColNo = intCurPos - intColNo1 '- 1 '+ 1

        Return intColNo

        'intLineNo   为行号，注意是从0开始的  
        'intColNo   为列号 
    End Function

    Public Function GetCurrentWord() As KeyValue.INILineWord
        Dim tmp1 As Integer = CheckRow2()

        Dim currentLine As String
        Dim tmpLine As String()
        Dim currentCol As Integer = CheckCol(rtfText)

        Dim LineSplited As New ArrayList
        Dim currentChars As Integer = 0
        Dim currentWord As String = "SYSTEM:NOTHING"

        Dim equalCharIndex As Integer
        Dim ReturnType As KeyValue.INILineWord

        If UBound(rtfText.Lines) < tmp1 Then
            currentLine = ""
        Else
            currentLine = rtfText.Lines(tmp1)
            currentLine = Trim(currentLine.Replace("" & Chr(9) & "", " ")) '.Replace("		", "")
            currentLine = Trim(currentLine.Split(Chr(9))(0))
        End If

        currentLine = Trim(currentLine.Split(";")(0))
        tmpLine = currentLine.Split("=")
        LineSplited.Add(tmpLine(0))

        'tmpLine = tmpLine(1).Split(",")
        tmpLine = tmpLine(UBound(tmpLine)).Split(",")

        For Each Unit In tmpLine
            LineSplited.Add(Unit)
        Next

        equalCharIndex = InStr(currentLine, "=")

        For Each Unit As String In LineSplited

            currentChars = currentChars + Unit.Length
            If currentChars >= currentCol Then
                currentWord = Unit
                Exit For
                'ElseIf currentChars + 1 = currentCol Then
                'currentWord = Unit
                'Exit For
            End If

        Next

        If currentWord = "SYSTEM:NOTHING" Then

            currentWord = LineSplited(LineSplited.Count - 1)

        End If

        ReturnType.LineType = "SYSTEM:EMPTYANDREADY"

        If equalCharIndex > 0 Then

            If currentCol + 1 > equalCharIndex Then
                ReturnType.LineType = "SYSTEM:AFTEREQUALCHARS"
            Else
                ReturnType.LineType = "SYSTEM:BEFOREQUALCHARS"
            End If

        Else
            ReturnType.LineType = "SYSTEM:NOEQUALCHARS"
        End If

        ReturnType.WordContext = currentWord
        Return ReturnType

    End Function

    Private Sub lstAutoC_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lstAutoC.KeyDown
        rtfText.Focus()
    End Sub

    Private Sub lstAutoC_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lstAutoC.KeyUp
        If lstAutoC.FindString(GetCurrentWord.WordContext) >= 0 Then

            bAllowCodeColor = False

            Dim tmpInt As Integer = GetCurrentWord.WordContext.Length + 1

            Dim orgSS As Integer = rtfText.SelectionStart

            If e.KeyCode = Keys.Space Then
                'rtfText.Lines(CheckRow2) = rtfText.Lines(CheckRow2).Remove(CheckCol(rtfText) - tmpInt, tmpInt)
                rtfText.Text = rtfText.Text.Remove(rtfText.SelectionStart - tmpInt, tmpInt)
                orgSS = orgSS - tmpInt
                rtfText.SelectionStart = orgSS
                If lstAutoC.SelectedItem <> Nothing Then
                    rtfText.Text = rtfText.Text.Insert(rtfText.SelectionStart, lstAutoC.SelectedItem)
                    CodeColor4()
                End If
            End If

            rtfText.SelectionStart = orgSS + Len(lstAutoC.SelectedItem)
            rtfText.Select()

            'If e.KeyCode <> Keys.Delete Then
            lstAutoC.Visible = False
            'Else
            'lstAutoC.Visible = True

            'End If
            bAllowCodeColor = True
        End If
    End Sub

    Private Sub cmdReg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdReg.Click, cmdRegP.Click
        Dim regForm As New frmReg(Me)
        regForm.Show()
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Dim tmpReg1 As RegClass.RegUnit
        tmpReg1 = cReg.GetRegInfoArray(iSection)
        lstAutoC.Items.Clear()
        For Each Section In tmpReg1.UnitName
            'trvCom.Nodes.Add(Section)
            lstAutoC.Items.Add(Section)
        Next
        lstAutoC.Visible = True
    End Sub

    Private Sub CodeColor4()
        Dim VB_OPERATORS As String = "&,+,-,*,/,\,^,>,<,>=,<=,<>,=,%"
        Dim VB_KEYWORDS As String = "Access,AddressOf,Alias,And,Any,AppActivate,Append,Array,As,Base,Beep,Binary,Boolean,ByRef,ByVal,Byte," _
        & "Cancel,Call,Case,ChDir,ChDrive,Choose,Close,Collection,Compare,Const,Currency,Declare,Dim,Do,DoEvents,Double," _
        & "Each,Else,ElseIf,Empty,End,Enum,Environ,Erase,Err,Error,Exit,Explicit,False,FileCopy,For,Form,Function,Get,GoSub,GoTo," _
        & "If,In,Input,Integer,Is,Kill,Let,Lib,Like,Line,Load,Lock,Long,Loop,Me,MkDir,Mod,Module,MsgBox,New,Next," _
        & "Not,Nothing,Null,Object,On,Open,Option,Optional,Or,Output,Print,Print,Private,Property,private,Put," _
        & "ReDim,Read,Reset,Resume,Return,RmDir,Seek,Select,SendKeys,Set,SetAttr,Shared,Shell,Single,Static,Step,Stop,String," _
        & "Sub,Switch,Tab,Then,To,True,Type,TypeName,Unlock,Until,Variant,Wend,While,With,Write,Xor"
        Dim VB_FUNCTIONS As String = "Abs,Asc,Atn,CBool,CByte,CCur,CDate,CDbl,CDec,CInt,CLng,CSng,CStr,CVErr,CVar,Chr,Command," _
        & "Cos,CreateObject,CurDir,DDB,Date,DateAdd,DateDiff,DatePart,DateSerial,DateValue,Day,DeleteSetting,EOF," _
        & "Eqv,Exp,FV,FileAttr,FileDateTime,FileLen,Filter,Fix,Format,FormatCurrency,FormatDateTime,FormatNumber,FormatPercent,FreeFile," _
        & "GetAllSettings,GetAttr,GetObject,GetSetting,Hex,Hour,IIf,IPmt,IRR,Imp,InStr,InStrRev,InputBox," _
        & "IsArray,IsDate,IsEmpty,IsError,IsMissing,IsNull,IsNumeric,IsObject,Join,LBound,LCase,LOF,LSet,LTrim,Left,Len," _
        & "LoadPicture,LoadResData,LoadResPicture,LoadResString,Loc,Log,MIRR,MacID,MacScript,Mid,Minute,Month,MonthName," _
        & "NPV,NPer,Now,Oct,PPmt,QBColor,RGB,RSet,RTrim,Random,Randomize,Rate,Replace,Right,Rnd,Round,SLN,SYD,SaveSetting,Second," _
        & "Sgn,Sin,Space,Split,Sqr,StrComp,StrConv,StrReverse,Tan,Time,TimeSerial,TimeValue,UBound,UCase,Val,VarPtr,VarType," _
        & "Weekday,WeekdayName,,Year"
        Dim VB_REDWORD As String = "yes,no,true,false"
        rtfText.Rtf = CCD.GetCodeedColorRTF(rtfText.Text, "", ccdFunctions, "", VB_REDWORD)

        'Dim fntF As New FontFamily("微软雅黑")
        'rtfText.Font = New Font(fntF, 10)
    End Sub

    Private Sub rtfText_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles rtfText.KeyDown
        orgSS = rtfText.SelectionStart

        If e.KeyCode = Keys.ControlKey Then
            rtfCtrlKey = True
        End If
        If e.KeyCode = Keys.Alt Then
            rtfAltKey = True
        End If

        Select Case e.KeyCode
            Case Keys.Down

                If lstAutoC.Visible = True Then
                    If lstAutoC.SelectedIndex + 1 >= 0 And lstAutoC.SelectedIndex + 1 <= lstAutoC.Items.Count - 1 Then
                        lstAutoC.SelectedIndex = lstAutoC.SelectedIndex + 1
                    End If
                End If

                e.Handled = True
            Case Keys.Up

                If lstAutoC.Visible = True Then
                    If lstAutoC.SelectedIndex - 1 >= 0 Then
                        lstAutoC.SelectedIndex = lstAutoC.SelectedIndex - 1
                    End If
                End If

                e.Handled = True
            Case Else
                If e.KeyCode <> Keys.Space Then
                    If lstAutoC.Visible = True Then
                        lstAutoC.Visible = False
                    End If
                End If
        End Select

    End Sub

    Private Sub rtfText_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles rtfText.KeyUp
        bAllowCodeColor = False

        Select Case e.KeyCode
            'Case Keys.Down
            ' If lstAutoC.Visible = True Then
            'If lstAutoC.SelectedIndex + 1 >= 0 Then
            'lstAutoC.SelectedIndex = lstAutoC.SelectedIndex + 1
            'End If
            'End If
            'rtfText.SelectionStart = orgSS
            'Case Keys.Up
            ' If lstAutoC.Visible = True Then
            'If lstAutoC.SelectedIndex - 1 >= 0 Then
            ' lstAutoC.SelectedIndex = lstAutoC.SelectedIndex - 1
            'End If
            'End If
            'rtfText.SelectionStart = orgSS
            Case Keys.Left, Keys.Right, Keys.Enter ', Keys.CapsLock
                Return
                'Case Else
                'If lstAutoC.Visible = True Then
                'lstAutoC.Visible = False
                'End If
        End Select

        If e.KeyCode = Keys.Space Then
            If lstAutoC.Visible = True Then lstAutoC_KeyUp(lstAutoC, e)
        ElseIf e.KeyCode = Keys.Escape Then
            lstAutoC.Visible = False
        ElseIf lstAutoC.Visible = False Or e.KeyCode = Keys.Delete Or e.KeyCode = Keys.Back Then
            If e.Control = False And e.KeyCode >= Keys.A And e.KeyCode <= Keys.Z Or e.Control = False And e.KeyCode >= Keys.D0 And e.KeyCode <= Keys.D9 Or e.Control = False And e.KeyCode >= Keys.NumPad0 And e.KeyCode <= Keys.NumPad9 Then

                If lstAutoC.FindString(GetCurrentWord.WordContext) >= 0 And GetCurrentWord.LineType = "SYSTEM:AFTEREQUALCHARS" Then
                    lstAutoC.Items.Clear()
                    lstAutoC.Items.AddRange(lstAutoCObject.Items)
                    If lstAutoC.FindString(GetCurrentWord.WordContext) >= 0 Then
                        lstAutoC.SelectedIndex = lstAutoC.FindString(GetCurrentWord.WordContext)
                    Else
                        lstAutoC.SelectedIndex = 0
                    End If
                    lstAutoC.Visible = True
                ElseIf lstAutoC.FindString(GetCurrentWord.WordContext) < 0 And GetCurrentWord.LineType = "SYSTEM:AFTEREQUALCHARS" Then
                    lstAutoC.Items.Clear()
                    lstAutoC.Items.AddRange(lstAutoCObject.Items)
                    lstAutoC.SelectedIndex = 0
                    lstAutoC.Visible = True
                ElseIf GetCurrentWord.LineType = "SYSTEM:BEFOREQUALCHARS" Or GetCurrentWord.LineType = "SYSTEM:NOEQUALCHARS" Then
                    lstAutoC.Items.Clear()
                    lstAutoC.Items.AddRange(lstAutoCRules.Items)
                    If lstAutoC.FindString(GetCurrentWord.WordContext) >= 0 Then
                        lstAutoC.SelectedIndex = lstAutoC.FindString(GetCurrentWord.WordContext)
                    Else
                        lstAutoC.SelectedIndex = 0
                    End If
                    lstAutoC.Visible = True
                End If
            Else
                rtfCtrlKey = False
            End If
        End If

        'lstAutoC.Focus()
        'lstAutoC.Select()
        bAllowCodeColor = True
        'rtfText.SelectionStart = orgSS
        If e.KeyCode = Keys.ControlKey Then
            rtfCtrlKey = False
        End If
        If e.KeyCode = Keys.Alt Then
            rtfAltKey = False
        End If
        If e.Control = True Then
            rtfCtrlKey = False
        End If
    End Sub

    Private Sub rtfText_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles rtfText.MouseUp
        If rtfCtrlKey = True And e.Button = Windows.Forms.MouseButtons.Right Then
            rtfText.Focus()
            rtfText.Select()
            cmdAllCom_Click()
        End If
    End Sub

    Private Sub cmdOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOpen.Click, cmdOpenP.Click
        LoadFile(0)
    End Sub

    Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click, cmdSaveP.Click
        SaveCurrentINI()
    End Sub

    Public Sub SaveINI()

        If iSection IsNot Nothing Then
            'SaveFile.InitialDirectory = "c:\"
            SaveFile.Filter = "INI文件 (*.ini)|*.ini|所有文件 (*.*)|*.*"
            SaveFile.FileName = GetSafeFileName(currentFile)
            'SaveFile.RestoreDirectory = True

            iSection(lstSection.SelectedIndex).SectionContext = rtfText.Text

            If SaveFile.ShowDialog() = DialogResult.OK Then
                Dim tmp As String
                tmp = cSection.RefreshSectionToFile(iSection, SaveFile.FileName)
                UpdateObjectListArray()
                currentFile = SaveFile.FileName
                Me.Text = GetSafeFileName(SaveFile.FileName)
                Dim ParentForm As frmMDIParent
                ParentForm = DirectCast(Me.MdiParent, frmMDIParent)
                If ParentForm.RecentFile.IndexOf(currentFile) < 0 Then
                    ParentForm.RecentFile.Insert(0, currentFile)
                    ParentForm.EightNumberRFA()
                    ParentForm.RefreshRecentFileMenuItem()
                End If
                Modifyed = False
            End If

        End If

    End Sub

    Public Sub SaveCurrentINI()

        If iSection IsNot Nothing Then
            Dim tmp As String
            iSection(lstSection.SelectedIndex).SectionContext = rtfText.Text
            tmp = cSection.RefreshSectionToFile(iSection, currentFile)
            UpdateObjectListArray()
            Modifyed = False
        End If

    End Sub

    Private Sub cmdDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDel.Click
        lstBookmark.Items.RemoveAt(lstBookmark.SelectedIndex)
        lstBookmark.SelectedIndex = lstBookmark.Items.Count - 1
    End Sub

    Private Sub lstBookmark_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstBookmark.SelectedIndexChanged

        allowAddBookmark = False
        lstSection.SelectedIndex = lstSection.FindStringExact(lstBookmark.SelectedItem)
        allowAddBookmark = True

    End Sub

    Private Sub cmdBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBack.Click
        If lstBookmark.SelectedIndex >= 0 Then lstBookmark.SelectedIndex = lstBookmark.SelectedIndex - 1
    End Sub

    Private Sub cmdForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdForward.Click
        If lstBookmark.SelectedIndex <> lstBookmark.Items.Count - 1 Then lstBookmark.SelectedIndex = lstBookmark.SelectedIndex + 1
    End Sub

    Private Sub cmdDelSection_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelSection.Click

        allowAddBookmark = False

        Dim orgLocation As Integer = lstSection.SelectedIndex
        Dim orgItem As String = lstSection.SelectedItem.ToString

        If lstBookmark.FindStringExact(lstSection.SelectedItem) >= 0 Then
            lstBookmark.Items.RemoveAt(lstBookmark.FindStringExact(lstSection.SelectedItem))
        End If

        iSection = cSection.DeleteSection(iSection, orgLocation)

        lstSection.Items.Clear()

        For Each root As KeyValue.INISection In iSection
            If root.SectionName <> Nothing Then lstSection.Items.Add(root.SectionName)
        Next

        lstSection.SelectedIndex = orgLocation

        'For i = 0 To lstBookmark.Items.Count - 1
        'If lstBookmark.Items(i).ToString = orgItem Then lstBookmark.Items.RemoveAt(i)
        'Exit For
        'Next

        allowAddBookmark = True

    End Sub

    Private Sub frmMain_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.TextChanged
        Me.Show()
        Dim wIndex As Integer = 0

        For Each Window As frmMain In frmMDIParent.fWindows
            If Me.Equals(Window) Then
                Exit For
            End If
            wIndex = wIndex + 1
        Next
        If frmMDIParent.tooSWind.Items.Count - 1 >= wIndex Then frmMDIParent.tooSWind.Items(wIndex).Text = Me.Text

        lblText.Text = "您正在编辑的文件 : " + Me.Text

        If Me.MdiParent IsNot Nothing Then
            Dim ParentForm As frmMDIParent
            ParentForm = DirectCast(Me.MdiParent, frmMDIParent)

            ParentForm.stlFile.Text = "Editing : " + Me.Text
        End If
    End Sub

    Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

        If Modifyed = True Then

            Dim sFMsg As MsgBoxResult
            sFMsg = MsgBox("您的修改尚未保存，要保存么？", MsgBoxStyle.YesNoCancel + MsgBoxStyle.Information, "INI编辑器 V2 警告")
            If sFMsg = MsgBoxResult.Cancel Then
                e.Cancel = True
                Exit Sub
            ElseIf sFMsg = MsgBoxResult.Yes Then
                SaveCurrentINI()
            End If

        End If

        Me.Show()
        Dim wIndex As Integer = 0

        For Each Window As frmMain In frmMDIParent.fWindows
            If Me.Equals(Window) Then
                frmMDIParent.fWindows.RemoveAt(wIndex)
                frmMDIParent.tooSWind.Items.RemoveAt(wIndex)
                Exit For
            End If
            wIndex = wIndex + 1
        Next

        Dim ParentForm As frmMDIParent
        ParentForm = DirectCast(Me.MdiParent, frmMDIParent)
        If ParentForm.fWindows.Count >= 1 Then
            If wIndex - 1 >= 0 Then
                ParentForm.fWindows(wIndex - 1).Show()
            Else
                ParentForm.fWindows(ParentForm.fWindows.Count - 1).Show()
            End If
        Else
            ParentForm.ShowNewForm(True, False)
        End If

    End Sub

    Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClose.Click, cmdCloseP.Click
        Me.Close()
    End Sub

    Public Sub UpdateObjectListArray()
        lstAutoCObject.Items.Clear()
        For Each Section In iSection
            lstAutoCObject.Items.Add(Section.SectionName)
        Next
    End Sub

    Private Sub lstAutoC_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstAutoC.SelectedIndexChanged
        'If lstAutoC.Items.Equals(lstAutoCRules.Items) Then
        If GetCurrentWord.LineType <> "SYSTEM:AFTEREQUALCHARS" Then
            Dim currentItemIndex As Integer
            currentItemIndex = RulesCodeData.CodeName.IndexOf(lstAutoC.SelectedItem)
            If currentItemIndex >= 0 Then
                If RulesCodeData.CodeMean.Count - 1 >= currentItemIndex Then
                    Dim ParentForm As frmMDIParent
                    ParentForm = DirectCast(Me.MdiParent, frmMDIParent)
                    ParentForm.stlMean.Text = RulesCodeData.CodeMean(currentItemIndex)
                    'lstAutoC.t()
                End If
            End If
            'Else
            'Dim ParentForm As frmMDIParent
            'ParentForm = DirectCast(Me.MdiParent, frmMDIParent)
            'ParentForm.stlMean.Text = cReg.ProduceRegStr(cReg.GetSectionRegInfo(tmpReg, lstAutoC.SelectedItem))
        End If
        ' End If
    End Sub

    Private Sub cmdSaveAsP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSaveAsP.Click
        SaveINI()
    End Sub

    Private Sub rtfText_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles rtfText.KeyPress
        Modifyed = True
    End Sub

    Private Sub cmdAllCom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAllComP.Click, cmdAllCom.Click

    End Sub

    Private Sub txtSFind_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles txtSFind.DragDrop
        txtSFind.Text = e.Data.GetData(DataFormats.Text)
    End Sub

    Private Sub txtSFind_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles txtSFind.DragEnter
        If (e.Data.GetDataPresent(DataFormats.Text)) Then
            e.Effect = DragDropEffects.Copy
        Else
            e.Effect = DragDropEffects.None
        End If
    End Sub

    Private Sub txtSFind_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtSFind.KeyUp
        If e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Space Then
            cmdSFind_Click()
        End If
    End Sub

    Private Sub txtSFind_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSFind.TextChanged

    End Sub

    Private Sub cmdSFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSFind.Click

    End Sub

    Private Sub cmdRename_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRename.Click
        rtfText.Text = Replace(rtfText.Text, "[" + Trim(lstSection.SelectedItem) + "]", "[" + Trim(txtSFind.Text) + "]", 1, 1, CompareMethod.Text)
        iSection(lstSection.SelectedIndex).SectionContext = Replace(iSection(lstSection.SelectedIndex).SectionContext, "[" + Trim(lstSection.SelectedItem) + "]", "[" + Trim(txtSFind.Text) + "]", 1, 1, CompareMethod.Text)
        iSection(lstSection.SelectedIndex).SectionName = Trim(txtSFind.Text)
        Dim orgLocation = lstSection.SelectedIndex

        lstSection.Items.Clear()
        For Each root As KeyValue.INISection In iSection
            If root.SectionName <> Nothing Then
                lstSection.Items.Add(root.SectionName)
            End If
        Next

        lstSection.SelectedIndex = orgLocation
    End Sub

    Private Sub cmdFindPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFindPrevP.Click, cmdFindPrev.Click

    End Sub

    Private Sub cmdFindNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFindNextP.Click, cmdFindNext.Click

    End Sub

    Private Sub rtfText_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles rtfText.DragEnter
        If (e.Data.GetDataPresent(DataFormats.Text)) Then
            e.Effect = DragDropEffects.Copy
        Else
            e.Effect = DragDropEffects.None
        End If
    End Sub

    Private Sub rtfText_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles rtfText.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Right Then
            rtfText.SelectionStart = rtfText.GetCharIndexFromPosition(New Point(e.X, e.Y))
        End If
    End Sub

End Class
